Add new sort function for testing
authorjustbur <justin@burkett.cc>
Thu, 8 Oct 2015 12:16:26 +0000 (08:16 -0400)
committerjustbur <justin@burkett.cc>
Thu, 8 Oct 2015 12:16:26 +0000 (08:16 -0400)
This is a variation on key order, which uses alphabetical sorting for
characters, putting lowercase before uppercase.

@syl20bnr

which-key.el

index 274bea5f562e7bf8736584b70b2f00740436b614..621586ae867874d6d266ba5c1059585822abd226 100644 (file)
@@ -1067,6 +1067,50 @@ alists. Returns a list (key separator description)."
          (list key-w-face sep-w-face desc-w-face)))
      unformatted)))
 
+(defun which-key--alpha< (a b)
+  (let ((da (downcase a))
+        (db (downcase b)))
+    (if (string-equal da db)
+        (not (string-lessp a b))
+      (string-lessp da db))))
+
+(defun which-key--key-description-alpha< (a b)
+  "Sorting function used for `which-key-key-order-alpha'."
+  (let* ((aem? (string-equal a ""))
+         (bem? (string-equal b ""))
+         (a1? (= 1 (length a)))
+         (b1? (= 1 (length b)))
+         (srgxp "^\\(RET\\|SPC\\|TAB\\|DEL\\|LFD\\|ESC\\|NUL\\)")
+         (asp? (string-match-p srgxp a))
+         (bsp? (string-match-p srgxp b))
+         (prrgxp "^\\(M\\|C\\|S\\|A\\|H\\|s\\)-")
+         (apr? (string-match-p prrgxp a))
+         (bpr? (string-match-p prrgxp b)))
+    (cond ((or aem? bem?) (and aem? (not bem?)))
+          ((and asp? bsp?)
+           (if (string-equal (substring a 0 3) (substring b 0 3))
+               (which-key--key-description< (substring a 3) (substring b 3))
+             (string-lessp a b)))
+          ((or asp? bsp?) asp?)
+          ((and a1? b1?) (which-key--alpha< a b))
+          ((or a1? b1?) a1?)
+          ((and apr? bpr?)
+           (if (string-equal (substring a 0 2) (substring b 0 2))
+               (which-key--key-description< (substring a 2) (substring b 2))
+             (string-lessp a b)))
+          ((or apr? bpr?) apr?)
+          (t (string-lessp a b)))))
+
+(defsubst which-key-key-order-alpha (acons bcons)
+  "Order key descriptions A and B.
+Order is lexicographic within a \"class\", where the classes and
+the ordering of classes are listed below.
+
+special (SPC,TAB,...) < single char < mod (C-,M-,...) < other.
+Sorts single characters alphabetically with lowercase coming
+before upper."
+  (which-key--key-description-alpha< (car acons) (car bcons)))
+
 (defun which-key--key-description< (a b)
   "Sorting function used for `which-key-key-order'."
   (let* ((aem? (string-equal a ""))